<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
	'id'=>'banner-master-form',
	'htmlOptions'=>array('enctype'=>'multipart/form-data'),
	'enableAjaxValidation'=>false,
)); ?>

	<div class="">Fields with <span class="required">*</span> are required.</div>

	<div class="">
	<?php echo $form->errorSummary($model); ?>
	</div>
	
	<?php echo $form->dropDownListRow($model,'page_id',CHtml::listData(PageMaster::getList('ALL'), 'page_id', 'page_name'),array('class'=>'span5','empty'=>'Select Page',
	'ajax'=>array(
		'type'=>'POST',
		'url'=>ApplicationConfig::getURL("", "pageLocationMapping", "locationListByPage",array()),
		'update'=>'#BannerMaster_banner_position',
		)
	
	)); ?>

	<?php
	if($model->banner_id == "")
	{
		echo $form->dropDownListRow($model,'banner_position',array(),array('class'=>'span5','empty'=>'Select Location')); 
	}
	else
	{
		echo $form->dropDownListRow($model,'banner_position',CHtml::listData(PageLocationMapping::getList('LOCATIONS-BY-PAGE', array('page_id'=>$model->page_id)), 'mapping_id', 'location_name'),array('class'=>'span5','empty'=>'Select Page',));
	}
	
	?>
		
	<?php echo $form->textFieldRow($model,'page_url',array('class'=>'span5','maxlength'=>200)); ?>
	
	<div class="row">
			<?php echo $form->labelEx($model,'start_date',array('class'=>'span5')); ?>
	</div>
	<div class="row" style="margin-left: 0px;">
	<?php 
		$this->widget('zii.widgets.jui.CJuiDatePicker', array(
		'model' => $model,
		'attribute' => 'start_date',
		'language' => 'en',
		'options'=>array('dateFormat' => 'yy-mm-dd'),
		'htmlOptions' => array(
		'size' => '10',         // textField size
		'maxlength' => '10',    // textField maxlength
		'class'=>'',
		'id'=>'start_date'
		
		),
		));    
	?>
    </div>
	<div class="row">
			<?php echo $form->labelEx($model,'end_date',array('class'=>'span5')); ?>
	</div>
	<div class="row" style="margin-left: 0px;">
	<?php 
		$this->widget('zii.widgets.jui.CJuiDatePicker', array(
		'model' => $model,
		'attribute' => 'end_date',
		'language' => 'en',
		'options'=>array('dateFormat' => 'yy-mm-dd'),
		'htmlOptions' => array(
		'size' => '10',         // textField size
		'maxlength' => '10',    // textField maxlength
		'class'=>'',
		'id'=>'end_date'
		
		),
		));    
	?>
    </div>
	
	<?php // echo $form->radioButtonListRow($model,'banner_type',ApplicationConfig::app()->params['scaling_params']['banner_type'],array('separator'=>'','onclick'=>'setOption(this);')); ?>
	
	<?php echo $form->radioButtonListRow($model,'type',array('code'=>'Image code','image'=>'Upload image','widget'=>'Widget Files') ,array('separator'=>'&nbsp;','onclick'=>'toggleimg(this.value);')); ?>
	
	<div id="code1" ><?php echo $form->textFieldRow($model,'banner_code',array('class'=>'span5','id'=>'code')); ?>
	</div>
	
	<div id="image1">
	<?php echo $form->fileFieldRow($model,'image',array('class'=>'span3','id'=>'image')); ?>
	<?php 
	if($model->banner_id != '')
	{
	echo CHtml::image(Yii::app()->baseUrl."/uploads/banner/small/".$model->image,"",array("style" => "width: 50px;height:40px;","align"=>"")) ;
	}
	?>
	</div>
	
	<div id="widget1" ><?php echo $form->dropDownList($model,'widget_name',ApplicationConfig::app()->getBannerWidgets(),array('class'=>'span5','id'=>'widget', 'empty'=>'Select Widget')); ?>
	
	</div>
	<?php echo $form->textFieldRow($model,'sort_order',array('class'=>'span1')); ?>
	<?php echo $form->dropDownListRow($model,'ip_location',array('in'=>'India', 'uk'=>'UK'),array('empty'=>'Select Location')); ?>
	<?php echo $form->radioButtonListRow($model,'active',ApplicationConfig::app()->params['scaling_params']['status'],array('separator'=>'&nbsp;')); ?>

	

	<div class="form-actions">
		<?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType'=>'submit',
			'type'=>'primary',
			'label'=>$model->isNewRecord ? 'Create' : 'Save',
		)); ?>
		<?php echo CHtml::button('Cancel', array('submit' => array('admin'), 'class' => 'btn btn-primary')); ?>
	</div>

<?php $this->endWidget(); ?>
<script>
$(function() {
			$("#start_date").datepicker({minDate: 0});
			$("#end_date").datepicker({minDate: 0});
			
		});
		
$(document).ready(function(){


	if('<?php echo $model->banner_id; ?>' == "")
	{
			$('#code1').hide();
			$('#image1').hide();
			$('#widget1').hide();
	}
	else
	{
	
			$('#code1').hide();
			$('#image1').hide();
			$('#widget1').hide();
		$('#<?php echo $model->type; ?>1').show();
	}
});
		
		
	function toggleimg(val)
	{
		$('#widget1').hide();
		$('#image1').hide();
		$('#code1').hide();	
		
		if(val=='code')
		{
			$('#code1').show();
			$('#image').val('');
		}
		else if(val=='image')
		{
			$('#image1').show();
			$('#code').val('');
		}
		else if(val=='widget')
		{
			$('#widget1').show();
		}
		
	
	}	
</script>
